package com.guosheng.nettytest.two;

import com.guosheng.nettytest.TimeServerHandler;

import java.net.ServerSocket;
import java.net.Socket;

public class TimeServer {

    public static void main(String[] args){
        int port = 8080;
        ServerSocket server = null;
        try{
            server = new ServerSocket(port);
            System.out.println("the timeserver is start in port :" + port);
            Socket socket = null;
            //创建i/o任务线程池
            TimeServerHandlerExecutePool singleExecutor = new TimeServerHandlerExecutePool(10,5);
            while(true){
                socket = server.accept();
                singleExecutor.execute(new TimeServerHandler(socket));
            }
        }catch(Exception e){
            e.printStackTrace();
        }finally{
            try{
                if(server != null)
                    server.close();
                server = null;
            }catch(Exception e){
                e.printStackTrace();
            }
        }
    }


}
